<#assign tit>储值卡配卡</#assign>
<@page.html title=tit>
<script type="text/javascript">

  function addc() {
    var fm = getEl("fm_input");
    var shopCode = fm.shopCode.value;
    var shopName = fm.shopCode.options[fm.shopCode.selectedIndex].innerHTML;
    var cardType = fm.cardType.value;
    var typeName = fm.cardType.options[fm.cardType.selectedIndex].innerHTML;
    var cardCode = fm.cardCode.value;

    if(shopCode=="") {
      window.alert("请选择门店");
      return;
    }
    if(cardType=="") {
      window.alert("请选择卡类型");
      return;
    }
    if(cardCode=="" || cardCode.length!=19) {
      window.alert("请输入19位卡号");
      return;
    }

    var tb = getEl("tb_list");
    addtb(tb, cardCode, shopName, typeName, shopCode+","+cardCode+","+cardType);
  }

  function uploadSucc(data) {
    var tb = getEl("tb_list");
    if(!tb) return;
    var i, card;
    for(i=0; i<data.length; i++) {
      card = data[i];
      addtb(tb, card.cardCode, card.shopCode+" - "+card.shopName, card.typeName, card.shopCode+","+card.cardCode+","+card.cardType);
    }
  }
  function addtb(tb, no, shop, mm, cid) {
    var i, tr, td;
    for(i=0; i<tb.rows.length; i++) {
      if(tb.rows[i].cells[0].innerHTML==no)
      return false;
    }
    tr = tb.insertRow(-1);
    tr.setAttribute("cid", cid);
    td = tr.insertCell(-1);
    td.innerHTML = no;
    td = tr.insertCell(-1);
    td.innerHTML = shop;
    td = tr.insertCell(-1);
    td.innerHTML = mm;
    td = tr.insertCell(-1);
    td.innerHTML = '<img src="${_appPath!}/images/del.png" onclick="deli(this);" style="cursor:pointer;"/>';
    return true;
  }
  function deli(e) {
    var tr = e.parentNode.parentNode;
    tr.parentNode.deleteRow(tr.rowIndex);
  }

  function addSave() {
    var tb = getEl("tb_list");
    if(!tb) return;
    var arr = [];
    for(var i=0; i<tb.rows.length; i++)
      arr.push(tb.rows[i].getAttribute("cid"));
    if(arr.length==0) {
      window.alert("请添加卡号");
      return;
    }
    postJson("_add", "codes="+encodeURIComponent(arr.join("|")), postRet);
  }
  function postRet(data) {
    window.alert(data.msg);
    if(data.ret) {
      //getEl("fm_input").reset();
      window.location = window.location;
    }
  }

</script>
<div style="width:600px;">

  <div class="kbox">
    <form id="fm_input" method="post" onsubmit="return false;">
      <table class="input w4">
        <tr>
          <th width="20%">收卡门店</th>
          <td><select name="shopCode" req="收卡门店" class="w2"><option value="">--请选择--</option><#if shopName??><#list shopName as t><option value="${t.id}">${t.id} - ${t.name}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>配卡类型</th>
          <td><select name="cardType" req="配卡类型" class="w2"><option value="">--请选择--</option><#if cardType??><#list cardType as t><option value="${t.id!}">${t.name!}</option></#list></#if></select></td>
        </tr>
        <tr>
          <th>卡号</th>
          <td><input type="text" name="cardCode" value="" req="卡号" class="w2" maxlength="20"></td>
        </tr>

      </table>
      <div class="button"><input type="button" value="添加卡号" onclick="addc();">
        <#if canUpload??><input type="button" class="opwin" value="上传卡号(Excel文件)" onmouseover="setupl(this);"></#if></div>
    </form>
  </div>

  <div class="button"><input type="button" value="提交配卡" onclick="addSave();">
    <input type="button" value="查询配卡" onclick="window.open('list');" style="float:right;"></div>

    <div>
      <div class="lsinfo" style="margin-top:5px;"></div>
      <table class="list">
        <tr>
          <th width="42%">卡号</th>
          <th width="28%">收卡门店</th>
          <th width="20%">卡类型</th>
          <th></th>
        </tr>
      </table>
      <div id="div_list" style="max-height:270px; overflow-y:auto;">
        <table id="tb_list" class="list"></table>
      </div>
    </div>


</div>
<script type="text/javascript" src="${_appPath!}/js/upload2.js"></script>
<script type="text/javascript">initUpl("_upload");</script>
</@page.html>